home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / HFSHalfGateway / HFSRecipient.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  7.9 KB  |  298 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        HFSRecipient.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __HFSRECIPIENT__
  15. #include "HFSRecipient.h"
  16. #endif
  17.  
  18. #ifndef __UTILITIES__
  19. #include "Utilities.h"
  20. #endif
  21.  
  22. #ifndef __DEBUGGINGGEAR__
  23. #include "DebuggingGear.h"
  24. #endif
  25.  
  26. /***********************************|****************************************/
  27.  
  28. #pragma segment HFSRecipient
  29.  
  30. /***********************************|****************************************/
  31.  
  32. THFSRecipient::THFSRecipient(const RString& recipientName, Boolean responsible) :
  33.     fResponsible (responsible),
  34.     fRecipientType ('HFS '),
  35.     fExtensionValue (nil) ,
  36.     fStatus ( cUnknown )
  37. {
  38.  
  39.     fName = recipientName;
  40.     fResponsible = responsible;
  41.     
  42.     //    First, copy over the recipient name.  The name is the part of the constructor
  43.     //    string which preceeds the '/', '-', or '|' in the address.
  44.     for (unsigned short index = fName.dataLength-1; index > 0; --index) 
  45.     {
  46.         if ((fName.body[index] == '/') || (fName.body[index] == '-') || (fName.body[index] == '|')) {
  47.             fName.dataLength = index;
  48.         }
  49.     }
  50.     
  51.     fExtensionValue = nil;
  52.     fPathNameElements = 0;
  53.     for (index = 0; index < 8; ++index)
  54.         fPathNameItems[index] = nil;
  55.     
  56.     fDirectoryName.dataLength = 0;
  57.     
  58.     //    First, check whether this address is an extension-format, because it contains
  59.     //    a '/' character.  If it is this format, then extract the part before the '/'
  60.     //    and put it into the extensionValue part of the address.  Also put it in as
  61.     //    the recipientName.  The address has no path or dNode information.  Put the
  62.     //    four characters after the '/' into the address type field.
  63.     for (index = 0; index < recipientName.dataLength; ++index) {
  64.         if (recipientName.body[index] == '/') {
  65.             //    Sanity check that the type is == 4 characters
  66.             if (recipientName.dataLength - index <= 4) {
  67.                 keith << "THFSRecipient: '/' address format should be data/TYPE, where TYPE=an OSType." << endl;
  68.             }
  69.             fRecipientType = * (OSType *) &recipientName.body[index+1];
  70.             
  71.             //    Now copy the extension data into our fields.
  72.             fExtensionValue = FAILNewPtrClear(index);
  73.             for (short dataCopyIndex = 0; dataCopyIndex < index; ++dataCopyIndex) {
  74.                 fExtensionValue[dataCopyIndex] = recipientName.body[dataCopyIndex];
  75.             }
  76.             return;
  77.         }
  78.     }
  79.  
  80.     //    Find a '-' in the name -- if it exists, then there is a path name, and so
  81.     //    we need to strip it out.  We only look for path information if the address
  82.     //    is not an extension-type address.
  83.     if ( fExtensionValue == nil )
  84.     {    
  85.             for (index = 0; index < recipientName.dataLength; ++index) {
  86.             if (recipientName.body[index] == '-') {
  87.                 RString    temp;
  88.     
  89.                 while ( ( index < recipientName.dataLength) && 
  90.                         (recipientName.body[index] != '|') )
  91.                 {
  92.                     temp.dataLength = 0;            
  93.                     temp.charSet = smRoman;
  94.                     for (++index; ((index < recipientName.dataLength) && 
  95.                                     (recipientName.body[index] != '-') && 
  96.                                     (recipientName.body[index] != '|')); ++index) {
  97.                         temp.body[temp.dataLength++] = recipientName.body[index];
  98.                     }
  99.         
  100.                     //    Now make a copy of it.
  101.                     if ( temp.dataLength )
  102.                     {
  103.                         fPathNameItems[fPathNameElements] = (RStringPtr) FAILNewPtrClear( sizeof(ProtoRString) + temp.dataLength);
  104.                         fPathNameItems[fPathNameElements]->charSet = temp.charSet;
  105.                         fPathNameItems[fPathNameElements]->dataLength = temp.dataLength;
  106.                         BlockMove ( temp.body, & fPathNameItems[fPathNameElements]->body, temp.dataLength );
  107.         
  108.                         ++fPathNameElements;
  109.                     }
  110.                 }
  111.                 
  112.                 //    And, since there's a path name component, change the type of this
  113.                 //    address to be the standard 20/20 recipient record type.
  114.                 fRecipientType = 'entn';
  115.             }
  116.         }
  117.     }
  118.     
  119.     //    If there is a '|' in the name, then the characters after that are the
  120.     //    directory name, so copy it over.
  121.     for (index = 0; index < recipientName.dataLength; ++index) {
  122.         if (recipientName.body[index] == '|') {
  123.             fDirectoryName.dataLength = recipientName.dataLength - index - 1;
  124.             fDirectoryName.charSet = smRoman;
  125.             BlockMove (&recipientName.body[index+1], &fDirectoryName.body[0], fDirectoryName.dataLength);
  126.             break;
  127.         }
  128.     }
  129. }
  130.  
  131. /***********************************|****************************************/
  132.  
  133. THFSRecipient::~THFSRecipient()
  134. {    
  135.     DisposeIfPtr(fExtensionValue);
  136.  
  137.     for (short index = 0; index < 8; ++index)
  138.         DeallocatePtr ((Ptr) fPathNameItems[index]);
  139. }
  140.  
  141. /***********************************|****************************************/
  142.  
  143. Boolean THFSRecipient::GetResponsible() const
  144. {
  145.     return fResponsible;
  146. }
  147.  
  148. /***********************************|****************************************/
  149.  
  150. Boolean THFSRecipient::GetRecipientName(TRString& name) const
  151. {
  152.     name = fName;
  153.     return true;
  154. }
  155.  
  156. /***********************************|****************************************/
  157.  
  158. Boolean THFSRecipient::GetRecipientType(TRString& type) const
  159. {
  160.     return false;
  161. }
  162.     
  163. /***********************************|****************************************/
  164.  
  165. Boolean THFSRecipient::GetDirectoryName(DirectoryName& directoryName) const
  166. {
  167.     if (fDirectoryName.dataLength > 0) {
  168.         directoryName = fDirectoryName;
  169.         return true;
  170.     }
  171.     return false;
  172. }
  173.         
  174. /***********************************|****************************************/
  175.  
  176. OSType THFSRecipient::GetAddressType() const
  177. {
  178.     return fRecipientType;
  179. }
  180.  
  181. /***********************************|****************************************/
  182.  
  183. unsigned short THFSRecipient::GetPathNameCount () const
  184. {
  185.     return fPathNameElements;
  186. }
  187.  
  188. /***********************************|****************************************/
  189.  
  190. void THFSRecipient::GetPathNameItem( unsigned short i, TRString &r ) const
  191. {
  192.     r.SetLength ( 0 );
  193.     r.SetScript ( smRoman );
  194.  
  195.     if ((i >= 0) && (i <= fPathNameElements))
  196.         r = *(fPathNameItems[i-1]);
  197. }
  198.         
  199. /***********************************|****************************************/
  200.  
  201. Boolean THFSRecipient::GetCID(CreationID& cid)  const
  202. {
  203.     unused(cid);
  204.     return false;
  205. }
  206.  
  207. /***********************************|****************************************/
  208.  
  209. unsigned long THFSRecipient::GetExtensionDataSize()  const
  210. {
  211.     return fName.dataLength;
  212. }
  213.  
  214. /***********************************|****************************************/
  215.  
  216. void THFSRecipient::GetExtensionData(unsigned long offset, void *buffer, unsigned long bufferSize) const
  217. {
  218.     unsigned long dataToMoveSize = longmin(GetExtensionDataSize() - offset, bufferSize);
  219.     BlockMove( (Ptr) (((char*) &fName.body)+offset), (Ptr) buffer, dataToMoveSize);
  220. }
  221.  
  222. /***********************************|****************************************/
  223.  
  224. Boolean
  225. THFSRecipient::SetStatus ( RecipientStatusSet status )
  226. {
  227.     fStatus = status;
  228.     return true;
  229. }
  230.  
  231. /***********************************|****************************************/
  232.  
  233. RecipientStatusSet
  234. THFSRecipient::GetStatus () const
  235. {
  236.     return fStatus;
  237. }
  238.  
  239. /***********************************|****************************************/
  240.  
  241. ostream& THFSRecipient::DescribeSubclass( ostream& s ) const
  242. {
  243.     s << "THFSRecipient:" << endl;
  244.     return s;
  245. }
  246.  
  247. /***********************************|****************************************/
  248.  
  249. //    This probably will never be called
  250. ostream& THFSRecipient::operator >> ( ostream& s ) const
  251. {
  252.     TRString            name;
  253.     
  254.     if (this == nil) {
  255.         s << "THFSRecipient: nil" << flush;
  256.         return s;
  257.     }
  258.  
  259.     s << "THFSRecpt: '";
  260.     if (GetRecipientName (name)) {
  261.         s << name << " ";
  262.     }
  263.     
  264.     s << "' status=" << GetStatus() << flush;
  265.     
  266.     return s;
  267. }
  268.     
  269. /***********************************|****************************************/
  270.  
  271. Boolean THFSRecipient::IsAddressTypePresent () const
  272. {
  273.     return fRecipientType != 'entn';
  274. }
  275.  
  276. /***********************************|****************************************/
  277.  
  278. Boolean THFSRecipient::IsPathInfoPresent () const
  279. {
  280.     return  false;
  281. }
  282.  
  283. /***********************************|****************************************/
  284.  
  285. Boolean THFSRecipient::IsPathInfoOptional () const
  286. {
  287.     return true;
  288. }
  289.  
  290. /***********************************|****************************************/
  291.  
  292. Boolean THFSRecipient::IsNameAndPathUnique ( ) const
  293. {
  294.     return true;
  295. }
  296.  
  297. /***********************************|****************************************/
  298.